package org.example.com.RocketMq.controller;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.example.com.RocketMq.dto.UserCharge;
import org.example.com.RocketMq.service.MQTXProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
public class RocketMqController {
    @Autowired
    private MQTXProducerService mqtxProducerService;

    @PostMapping("/charge")
    private LocalTransactionState charge(@RequestBody UserCharge userCharge) {
        TransactionSendResult sendResult = mqtxProducerService.sendHalfMsg(userCharge);
        LocalTransactionState localTransactionState = sendResult.getLocalTransactionState();
        return localTransactionState;
    }
}
